import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import '../../services/auth_service.dart';
import '../../widgets/menu_button.dart';

class HomeScreen extends StatelessWidget {
  const HomeScreen({super.key});

  @override
  Widget build(BuildContext context) {
    final user = Provider.of<AuthService>(context).currentUser;
    return Scaffold(
      appBar: AppBar(
        title: Row(

        children: [

          Text(

            'Welcome, ${user?.username ?? 'user'}',

            style: const TextStyle(fontSize: 16),

          ),

        ],

        ),
        // title: const Text('WMS'),
        automaticallyImplyLeading: false,
        actions: [
          IconButton(
            icon: const Icon(Icons.logout,color: Colors.white,),
            onPressed: () {
              Provider.of<AuthService>(context, listen: false).logout(context);
              // Navigator.pushNamed(context, '/login');
            } 
            
          ),
        ],
        backgroundColor: const Color(0xFF008363),
      ),
      body: Padding(
        padding: const EdgeInsets.all(32),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Expanded(
              child: GridView.count(
                crossAxisCount: 2,
                crossAxisSpacing: 16,
                mainAxisSpacing: 16,
                childAspectRatio: 1.3,
                children: [
                  MenuButton(
                    icon: Icons.input,
                    label: 'Inbound',
                    color: Colors.blue,
                    onTap: () => Navigator.pushNamed(context, '/inbound'),
                  ),
                  MenuButton(
                    icon: Icons.outbound_sharp,
                    label: 'Outbound',
                    color: Colors.orange,
                    onTap: () => Navigator.pushNamed(context, '/outbound'),
                  ),
                  MenuButton(
                    icon: Icons.inventory,
                    label: 'Inventory',
                    color: Colors.purple,
                    onTap: () => Navigator.pushNamed(context, '/inventory'),
                  ),
                  MenuButton(
                    icon: Icons.settings,
                    label: 'System',
                    color: Colors.grey,
                    onTap: () => Navigator.pushNamed(context, '/system'),
                  ),
                ],
              ),
            ),
          ],
        ),
      ),
    );
  }
}